import gevent
from locust import User, task, FastHttpUser, wait_time, constant



class UserHelloWorld(FastHttpUser):

    wait_time = constant(5)
    host = "http://www.baidu.com/"

    # @task
    # def hello_world(self):
    #     with self.rest('get', '/') as response:
    #         if response.status_code != 200:
    #             response.failure("请求失败")

    @task
    def t(self):
        # Concurrency 并发线程
        def concurrent_request(url):
            self.client.get(url)

        pool = gevent.pool.Pool()
        urls = ["/url1", "/url2", "/url3"]
        for url in urls:
            pool.spawn(concurrent_request, url)
        pool.join()


# locust -f base_example.py --headless --users 10 --spawn-rate 1 -H http://192.168.10.195:8080/jenkins/